<template>
	<view
		:style="'order:'+item.order+';'+item.css"
		class="my-mark-user">
		<template v-if="$_isLogin()">
			<template v-if="listStatus == 'success'">
				<view
					class="_for"
					v-for="item in list"
					@click="$_to('user/detail?uid=' + item.uid)">
					<view class="_avatar">
						<global-lazy-load-image
							:image="item.avatar"
							width="50rpx"
							height="50rpx"
							borderRadius="0"></global-lazy-load-image>
					</view>
					<view class="_nickname">{{item.nickname}}</view>
					<view
						class="_roleName"
						:style="'color:'+item.nicknameColor+';'">{{item.roleName}}</view>
					<view class="_right">
						<view @click.stop="clickMarkUserButton(item.uid)">
							<text class="iconfont icon-favorite"></text>
						</view>
						<view @click.stop="clickUserChatButton(item.uid)">私聊</view>
					</view>
				</view>
				<view
					class="more-content"
					@click="clickMoreButton">
					{{listPageText}}
				</view>
			</template>
			<template v-if="listStatus == 'loading'">
				<global-loading></global-loading>
			</template>
			<template v-if="listStatus == 'empty'">
				<view class="_empty">
					<view>
						<text class="iconfont icon-cry"></text>
						<text class="_text">
							<template v-if="markType === 'like'">
								暂无点赞
							</template>
							<template v-if="markType === 'dislike'">
								暂无点踩
							</template>
							<template v-if="markType === 'follow'">
								暂无收藏
							</template>
							<template v-if="markType === 'block'">
								暂无屏蔽
							</template>
						</text>
					</view>
				</view>
			</template>
		</template>
		<template v-else>
			<view class="no-login">
				<view>未登录，请登录</view>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		name:"my-mark-user",
		props:{
			item:{
				type:Object,
				default:null
			}
		},
		data() {
			return {
				list:[],
				listStatus:"loading",
				listPage:2,
				listPageText: this.$t('clickToLoadMore'),
				userUid:"",
				markType:this.item.markType
			};
		},
		mounted(){
			this.userUid = JSON.parse(uni.getStorageSync('accountAuthToken')).uid;
			this.getList();
		},
		methods: {
			getList(){
				this.$_request(
					"GET", `/api/fresns/v1/user/${this.userUid}/mark/${this.item.markType}/users`,
					{
						"filterType":"whitelist",
						"filterKeys":"fsid,uid,username,nickname,avatar,nicknameColor,roleName",
						"page":1
					},
					(res) => {
						if (res.data.data.list.length) {
							this.list = res.data.data.list;
							this.listStatus = "success";
						} else {
							this.listStatus = "empty";
						}
					}
				)
			},
			clickMoreButton(){
				if (this.listPageText == this.$t('loading')) { return }
				this.listPageText = this.$t('loading');
				this.$_request(
					"GET", `/api/fresns/v1/user/${this.userUid}/mark/${this.item.markType}/users`,
					{
						"filterType":"whitelist",
						"filterKeys":"fsid,uid,username,nickname,avatar,nicknameColor,roleName",
						"page": this.listPage
					},
					(res) => {
						if (res.data.data.list.length) {
							this.list = this.list.concat(res.data.data.list);
							this.listPage++
							this.listPageText = this.$t('clickToLoadMore')
						} else {
							this.listPageText = this.$t('listEmpty')
						}
					}
				)
			},
			clickMarkUserButton(uid){
				uni.showLoading();
				this.$_request(
					"POST","/api/fresns/v1/user/mark",
					{
						"markType":this.item.markType,
						"type":"user",
						"fsid":uid
					},
					(res) => {
						uni.hideLoading();
						if(res.data.code == 0 ){
							this.getList();
							this.listPage = 2;
							this.listPageText = this.$t('clickToLoadMore');
						}else{
							uni.showToast({
								title: res.data.message,
								icon: 'none',
								duration: 1500
							});
						}
					}
				)
			},
			clickUserChatButton(uid){
				uni.showModal({
					title: '私聊',
					content: '给TA说点什么？',
					confirmText: '发送',
					editable: true,
					success: (res) => {
						let c = res.content;
						if(res.confirm){
							if(!c){
								uni.showToast({
									title: '内容不得为空',
									icon: 'none',
									duration: 1500
								});
								return;
							}
							this.$_request(
								"POST","/api/fresns/v1/conversation/message",
								{
									"uidOrUsername":uid,
									"message": c
								},
								(ref) => {
									if(ref.data.code == 0){
										this.$_to('notification/conversation?uid=' + uid)
									}else{
										uni.showToast({
											title: ref.data.message,
											icon: 'none',
											duration: 1500
										});
									}
								}
							)
						}
					}
				});
			},
		},
	}
</script>

<style lang="scss" scoped>
.my-mark-user{
	background: #FFF;
	padding: 0 25rpx;
	.no-login{
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 25rpx;
		view{
			display: flex;
			align-items: center;
			justify-content: center;
			border: 1px solid $border;
			background: $background;
			padding: 25rpx 0;
			width: 100%;
		}
	}
	.more-content{
		padding: 25rpx 0;
		font-size: 22rpx;
		line-height: 22rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		color: $placeholder;
	}
	._empty{
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 25rpx 0;
		view{
			display: flex;
			align-items: center;
			justify-content: center;
			flex-flow: column;
			text{
				color: $placeholder;
			}
			.iconfont{
				font-size: 100rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				line-height: 100rpx;
			}
			._text{
				font-size: 28rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				line-height: 28rpx;
				padding-top: 25rpx;
			}
		}
	}
	._for{
		display: flex;
		align-items: center;
		border-bottom: 1px dotted $border;
		padding: 25rpx 0;
		._avatar{
			width: 50rpx;
			height: 50rpx;
			overflow: hidden;
			border-radius: 100%;
			flex-shrink: 0;
		}
		._nickname{
			font-size: 28rpx;
			line-height: 28rpx;
			flex-shrink: 0;
			padding-left: 10rpx;
		}
		._roleName{
			font-size: 22rpx;
			line-height: 22rpx;
			flex-shrink: 0;
			padding-left: 10rpx;
			color: $placeholder;
		}
		._right{
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: flex-end;
			view:nth-child(1){
				display: flex;
				align-items: center;
				line-height: 32rpx;
				background: $red;
				color: #FFF;
				padding: 0 15rpx;
				border-radius: 5rpx;
				margin-right: 25rpx;
				height: 48rpx;
				text{
					font-size: 32rpx;
				}
			}
			view:nth-child(2){
				display: flex;
				align-items: center;
				height: 48rpx;
				font-size: 22rpx;
				line-height: 22rpx;
				background: $theme;
				color: #FFF;
				padding: 0 15rpx;
				border-radius: 5rpx;
			}
		}
	}
}
</style>